﻿/**
 * @author sminutoli
 * version 1.0
 */
import com.dinmax.flash.central.bridge.*
import com.dinmax.flash.draw.cabeza.*

class CONSOLEBridge
extends ControlCabeza 
implements SelectedListener {
	
	private static var FRAME_LOGIN:String="login";
	private static var FRAME_USER:String="user";
	
	private var bridge:CENTRALBridge;
	private var logIn:LOGINBridge;
	private var rootExtension:EXTENSIONBridge;
	private var mcRootButtons:ROOTButtonsBridge;
	private var mcLogOut:ButtonCabeza;
	
	private var shortcuts:Array;
			
	public function CONSOLEBridge() {
		return;
	};
	
	public function onLoad():Void {
		super.onLoad(); // hace que se registre con el parent si es un control cabeza
		this.setBridge(CENTRALBridge.getActive());
		this.getBridge().setConsole(this);
		logIn.setBridge(this.getBridge());
	};
	
	public function initChild(control:ControlCabeza):Void {
		switch (control){
			case this.logIn:
			//trace("CONSOLEBridge.as initChild() "+logIn);
			break;
			
			case this.rootExtension:
			this.rootExtension.setBridge(this.getBridge());
			break;
			
			case this.mcLogOut:
			control.addListener(this);
			break;
			
			case this.mcRootButtons:
			mcRootButtons.setBridge(this);
			mcRootButtons.getDATARoot().setShortCuts(this.shortcuts);
			break;
			
		};
		return;
	};
	public function getLogIn():LOGINBridge {
		return logIn;
	}

	public function getRootExtension():EXTENSIONBridge {
		return rootExtension;
	}
	
	public function createRootExtension():EXTENSIONBridge {
		this.logIn.enabled = false;
		this.gotoAndStop(CONSOLEBridge.FRAME_USER);
		//trace("CONSOLEBridge.as createRootExtension() rootExtension "+rootExtension);
		return rootExtension;	
	};
	
	public function getRootButtons():ROOTButtonsBridge {
		//trace("CONSOLEBridge.as getRootButtons()= "+this.mcRootButtons);
		return this.mcRootButtons;
	};
	
	public function logOut():Void {
		//this.gotoAndStop(CONSOLEBridge.FRAME_LOGIN);
		bridge.logOut();	
		return;
	};
	
	public function setShortCuts(shortcuts:Array):Void {
		this.shortcuts = shortcuts;
		if(mcRootButtons){
			mcRootButtons.getDATARoot().setShortCuts(shortcuts);
		};
		return;
	};
	
	public function getBridge():CENTRALBridge {
		return bridge;
	}

	public function setBridge(bridge:CENTRALBridge):Void {
		this.bridge = bridge;
		//trace("CONSOLEBridge.as | setBridge() "+bridge);
	};
	
	public function selected(control:ControlCabeza):Void {
		if(control == this.mcLogOut) this.logOut();
		return;
	};

}